package com.atguigu.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.yygh.cmn.mapper.DictMapper;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Map;

@Component
public class DictListener extends AnalysisEventListener<DictEeVo> {
    @Autowired
    DictMapper dictMapper;

    //从第二行开始读取,一次读取一行
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        //创建Dict对象用于传入数据库
        Dict dict = new Dict();
        //将dictEeVo的属性值 复制 给Dict中
        BeanUtils.copyProperties(dictEeVo,dict);
        dictMapper.insert(dict);
    }
    //读取文件头信息
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
    }

    //读取完成后执行
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
